﻿

	var min = {

		submitPhones:function (){

				var riqi = this.getCurrentDate(2)

				var self = this

				$('#but').click(function(){

					var phones = $('#phones').val()

					var qudao_selectV = $('#qudao_select').val()

					if(phones == ''){

						alert('空值')

						return
					}

					if(qudao_selectV == '1'){

						alert('请选择渠道名称')

						return
					}



					phones = phones.replace(/\'|\"/,'')

					var phonesArr = phones.split("\n")

					var sqlP = ''

					var sqlPphone = ''

					for(var i = 0 ; i < phonesArr.length ; i++ ){

						var phone = phonesArr[i]

						if(phone.indexOf("\t") !==-1){

							var phoneQ = phone.split("\t")

							if(phoneQ.length<3){

								alert('该标签渠道至少需要三列数据')

								return
							}

							sqlP += ',(\''+ phoneQ[0] + '\',\'' + '客户' +i +  '\',\'' + qudao_selectV +  '\',\'' + riqi +  '\',\'' + phoneQ[1] +  '\',\'' + phoneQ[2] +  '\')'

							sqlPphone +=',\''+ phoneQ[0] + '\''

						}else{

							if (phone !==''){

								sqlP += ',(\''+ phone + '\',\'' + '客户' +i +  '\',\'' + qudao_selectV +  '\',\'' + riqi +  '\',\'\',\'\')'

								sqlPphone +=',\''+ phone + '\''
							}

						}	

					}

					

					self.getChongFuInfo("("+sqlPphone.substr(1,sqlPphone.length)+")",riqi)  //获取重复数据并展示

					sqlP = sqlP.substr(1,sqlP.length) + ';'

					$.post('php/tt.php',{'phones':sqlP,'type':1},function(data,status){

						console.log(data)

						data = JSON.parse(data)

						alert(data.msg)

						$('#phones').val('')
						$('#count_i').text('0条')

					})
				})  //提交改标签的客资
		},

		count:function (){

			$('#phones').keyup(function(){


				var phones = $(this).val()


				if(phones == ''){

					$('#count_i').text('0条')

					return
				}

				var phonesArr = phones.split("\n")

				var len = phonesArr.length - 1;

				$('#count_i').text(len + '条')

			})
		},

		submitWxPhones:function(){  //提交微信公众号的客资


				var self = this

				$('#but').click(function(){

					var phones = $('#phones').val()

					if(phones == ''){

						alert('空值')

						return
					}

					var phonesArr = phones.split("\n")


					var sqlP = ''

					var date = self.getCurrentDate(2) //获取当前时间


					var appname = self.getAppName()?self.getAppName():''

					if(!appname){

						alert('请选择公众号名称')

						return
					}

					for(var i = 0 ; i < phonesArr.length ; i++ ){

						var phone = phonesArr[i]

						if (phone !==''){

							sqlP += ',(\'' + phone.replace(/\t/,'\',\'') + '\',\'' + date + '\',\'' + appname + '\',\'公众号菜单栏' + '\',\'' + date + '\')'

	
						}

					}

					sqlP = sqlP.substr(1,sqlP.length) + ';'

					$.post('../php/tt.php',{'phones':sqlP,'type':2},function(data,status){

						console.log(data)

						data = JSON.parse(data)

						alert(data.msg)

						$('#phones').val('')

						$('#count_i').text('0条')

						var appNameLen = $('.appnames>div').length

						for(var i = 0; i < appNameLen ; i++){

						 	$($('.appnames>div')[i]).css({'background':'#fff','color':'black'})

						 }
					})
				})  
		},

		appNameFocus:function(){

			var self = this

			$('.appnames>div').click(function(){

				 var appname = $(this).text();

				 var appNameLen = $('.appnames>div').length

				 for(var i = 0; i < appNameLen ; i++){

				 	$($('.appnames>div')[i]).css({'background':'#fff','color':'black'})

				 }

				 $(this).css({'background':'red','color':'#fff'})


			})
		},
		getCurrentDate:function (format){


		      var now = new Date();
		      var year = now.getFullYear(); //得到年份
		      var month = now.getMonth();//得到月份
		      var date = now.getDate();//得到日期
		      var day = now.getDay();//得到周几
		      var hour = now.getHours();//得到小时
		      var minu = now.getMinutes();//得到分钟
		      var sec = now.getSeconds();//得到秒
		      month = month + 1;
		      if (month < 10) month = "0" + month;
		      if (date < 10) date = "0" + date;
		      if (hour < 10) hour = "0" + hour;
		      if (minu < 10) minu = "0" + minu;
		      if (sec < 10) sec = "0" + sec;
		      var time = "";
		      //精确到天
		      if(format==1){
		        time = year + "-" + month + "-" + date;
		      }
		      //精确到分
		      else if(format==2){
		        time = year + "-" + month + "-" + date+ " " + hour + ":" + minu + ":" + sec;
		      }

		      return time;
    	},

    	getAppName:function(){

    		var self = this

			var appNameLen = $('.appnames>div').length

			for(var i = 0; i < appNameLen ; i++){

			 	var fosueColor = $('.appnames>div')[i].style.background


			 	if (fosueColor == 'red'){

			 		var appname =$($('.appnames>div')[i]).text()

			 	}

			}


			if(appname){


				return appname;
			}else{


				return false;
			}
    	},

    	getAppNames:function(){

    		var self = this

    		$.post('../php/tt.php',{type:3},function(date,status){

    			if(status == 'success'){

    				var data = JSON.parse(date).data

    				var len = data.length;

    				$('#appnames').html('')

    				for(var i = 0; i < len ; i++){

    					var appname = data[i].appName

    					if(appname){

    						$li = `<div>${appname}</div>`

    						$('#appnames').append($li)
    					}

    				}

    				self.appNameFocus()

    			}
			
			})
    	},
    	//进度条
		progress:function(){

			var self = this;

			$.post('../mingxi.php',{type:43},function(data,statuss){

				var pgs = JSON.parse(data).data

				if(pgs[0].incomplete == 0){


					if(self.isShowProgress){


						$('#progressBox').html('')

						$('#progressBox').html(`<div class="progress_title">
		    				任务提交到呼叫系统进度：
		    			</div>
		    			
		    			<div class="progress_box">
		    				<div class="progress_jindu" id="progress">100%</div>
		    			</div>`)


						$('#progress').css({width:'100%'})


						setTimeout(function(){

							$('#progressBox').html('')

						},1000)


					}


					self.isShowProgress = false

					return
				}


				self.isShowProgress = true


				var incomplete = pgs[0].incomplete

				var total =  pgs[0].total

				var complete = total - incomplete

				var pre = Math.round(complete / total * 100)

				var pre = pre + '%'


				$('#progressBox').html('')

				$('#progressBox').html(
					`<div class="progress_title">
	    				任务提交到呼叫系统进度：
	    			</div>
	    			<div class="progress_box">
	    				<div class="progress_jindu" id="progress">${pre}</div>
	    			</div>`
    			)


				$('#progress').css({width:pre}).html(pre)


			})
		},
		//更新进度条
		upProgress:function(){



			var self = this;

			setInterval(function(){

				

				self.progress()

			},1000)
		},
		isShowProgress:false,
		getChongFuInfo:function(phones,riqi){ //获取重复的电话人明细

			var self = this

			$.post('php/tt.php',{'type':4,phones:phones,riqi:riqi},function(data,status){


				data = JSON.parse(data)

				if (data.count == 0){

					return
				}

				$('#text').text('重复数据明细（'+data.count+'）条')

				$('#cfTable_content').html('')

				$li=''

				for(var i = 0 ; i < data.data.length ; i++){

					$li= $li +  `
						<div class="cft_item">
							<div>${data.data[i].start_date}</div>
							<div>${data.data[i].link_url}</div>
						</div>
					`

				}

				$('#cfTable_content').html($li)

				self.showCfBox()

			})

		},
		showCfBox:function(){
			$('#chongFuAlter').show()
		},
		hideCfBox:function(){
			$('#chongFuAlter').hide()
		}

	}

